import java.util.Random;
import java.util.Scanner;

public class Java4 {

    public static void main(String[] args) {
        int n = 8;
        int m = 3;
        int c = 0;
        while (n % m != 0) {
            c = n % m;
            n = m;
            m = c;
        }
        System.out.println(m);
    }

    public static void main36(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入第一个整数");
        int n = scan.nextInt();
        System.out.println("请输入第二个整数");
        int m = scan.nextInt();
        int c = 0;
        while (n % m != 0) {
            c = n % m;
            n = m;
            m = c;
        }
        System.out.println(m);
    }

    public static void main35(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int n = scan.nextInt();
        int b = 0;
        int count = 0;
        while (n != 0) {
            b = n % 2;
            n = n / 2;
            if (b == 0) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main34(String[] args) {
        //输出1-100的素数
        int i=0;
        int j=0;
        for ( i = 2; i <= 100; i++) {
            for ( j = 2; j <= i; j++) {
                if (i % j == 0) {
                    break;
                }
            }
            if (i == j) {
                System.out.println(i+"是素数");
            }
        }
    }

    public static void main33(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        int m = scan.nextInt();
        int i = 0;
        for ( i = 2; i < m; i++) {
            if (m % i == 0) {
                System.out.println(m+"不是素数");
                break;
            }
        }
        if (i == m) {
            System.out.println(m + "是素数");
        }
    }

    public static void main32(String[] args) {
        for (int i = 1000; i <= 2000; i++) {
            if (i % 4 == 0 && i %100 != 0) {
                System.out.println(i);
                continue;
            }
            if (i % 400 == 0) {
                System.out.println(i);
            }
        }
    }

    public static void main31(String[] args) {
        int count = 0;
        for (int i = 9; i <= 100; i++) {
            if (i == 9) {
                count++;
                continue;
            }
            if (i % 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main30(String[] args) {
        boolean flag;
        for (int i = 2; i <= 100; i++) {
            flag = false;
            for (int j = 2; j <= i; j++) {
                if (i % j == 0) {
                    break;
                }
                flag = true;
            }
            if (flag) {
                System.out.println(i);
            }
        }
    }

    public static void main29(String[] args) {
        Random random = new Random(123);//固定随机数
        //int randNum = random.nextInt(100)+100;//[100-200)
        //int randNum1 = random.nextInt(50)+50;//[50-100)
        //Math.random();//作业
        int i = (int)(Math.random()*50);
        System.out.println(i);
        //System.out.println(randNum1);
    }

    public static void main28(String[] args) {
        //生成随机数
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        int randNum = random.nextInt(100);//[0-100)
        //System.out.println(randNum);
        while (true) {
            System.out.println("请输入你要猜的数字");
            int num = scan.nextInt();
            if (num > randNum) {
                System.out.println("猜大了");
            }else if (num == randNum) {
                System.out.println("猜中了");
                break;
            }else {
                System.out.println("猜小了");
            }
        }
    }

    public static void main27(String[] args) {
        Scanner scan = new Scanner(System.in);

        //ctrl+d停止循环
        //循环n个数字
        System.out.println("请输入数字");
        while (scan.hasNextInt()) {
            int n = scan.nextInt();
            System.out.println("n =" + n);
        }
    }

    public static void main26(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.println("请输入年龄：");
        int m = scan.nextInt();
        System.out.println(m);

        scan.nextLine();

        //此时 上边输完之后 回车 会被下面读取到
        System.out.println("请输入姓名：");
        String name = scan.nextLine();
        System.out.println(name);

    }

    public static void main25(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入姓名：");
        //遇到空格就结束了
        String name = scan.next();
        System.out.println(name);

        String name2 = scan.next();
        System.out.println(name2);
    }

    public static void main24(String[] args) {
        //在java当中，我们会用到java官方写好的一个工具（类）
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = scan.nextLine();
        System.out.println(name);

        System.out.println("请输入年龄：");
        int m = scan.nextInt();
        System.out.println(m);

        System.out.println("请输入你的工资：");
        double g = scan.nextDouble();
        System.out.println(g);

        scan.close();

    }

    public static void main23(String[] args) {
        //输出
        System.out.println("输出且换行");
        System.out.print("输出且不换行");
        System.out.printf("%s\n","格式化输出，和c语言一样");
    }

    public static void main22(String[] args) {
        //do-while循环（用的少）
        int i = 0;
        do {
            System.out.println(i);
            i++;
        }while (i <= 10) ;
    }

    public static void main21(String[] args) {
        //没有条件 默认死循环
        for (int i = 0; ; i++) {
            System.out.println("i");
        }
    }

    public static void main20(String[] args) {
        int sum = 0;
        for (int k = 1; k <= 5; k++) {
            int ret = 1;
            for (int i = 1; i <= k; i++) {
                ret *= i;
            }
            //System.out.println(ret);
            sum += ret;
        }
        System.out.println(sum);

    }

    public static void main19(String[] args) {
        //for(表达式1；布尔表达式2；表达式3) {
        //    循环体
        //fori
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }

    public static void main18(String[] args) {
        //找到既能被三整除也能被五整除 要求：使用break/continue
        int a = 1;
        while (a <= 100) {
            if (a % 3 == 0 && a % 5 == 0) {
                System.out.println(a);
                a++;
                continue;
            }
            a++;
        }
    }

    public static void main17(String[] args) {
        //break结束所有循环，剩余循环不会在执行了
        //continue结束本趟循环
        int a = 1;
        while (a <= 10) {
            if (a == 2) {
                a++;
                continue;
            }
            System.out.println(a);
            a++;
        }
    }

    public static void main16(String[] args) {
        //死循环
        while (true) {
            System.out.println("hello");
        }
    }

    public static void main15(String[] args) {
        int i = 1;
        int sum = 0;
        while (i <= 5) {
            int a = 1;
            int ret = 1;
            while (a <= i) {
                ret *= a;
                a++;
            }
            //System.out.println(ret);
            sum += ret;
            i++;
        }
        System.out.println(sum);
    }

    public static void main14(String[] args) {
        int a = 1;
        int ret = 1;
        while(a <= 5) {
            ret *= a;
            a++;
        }
        System.out.println(ret);
    }

    public static void main13(String[] args) {
        //求0-100的和
        int a = 1;
        int sum = 0;
        while (a <= 100) {
            sum = sum + a;
            a++;
        }
        System.out.println(sum);
        System.out.println("#############");
        //求0-100奇数和
        a = 1;
        int summ = 0;
        while (a <= 100) {
            summ += a;
            a += 2;
        }
        System.out.println(summ);
        System.out.println("#################");
        //求0-100偶数和
        a = 2;
        int summm = 0;
        while (a <= 100) {
            summm += a;
            a += 2;
        }
        System.out.println(summm);
    }


    public static void main12(String[] args) {
        //while for do-while
        int a = 1;
        //while里是布尔表达式
        while (a <= 5) {
            System.out.println(a);
            a++;
        }
        System.out.println("fffff");
    }

    public static void main11(String[] args) {
        //不能做switch的参数的数据类型是什么？long类型 float类型 double类型 boolean类型
        //不能有两个一样case
        //有复杂条件用if-else
        int a = 1;
        switch (a) {
            case 1:
                System.out.println("1");
                break;
            case 2:
                System.out.println("2");
                break;
            default:
                System.out.println("输入有误");
                break;
        }
    }

    public static void main10(String[] args) {
        int year = 2020;
        if (( year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
            System.out.println(year + "是闰年");
        }else {
            System.out.println(year + "不是闰年");
        }
    }

    public static void main9(String[] args) {
        int year = 2021;
        if ((year % 100 == 0 && year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
            System.out.println(year + "是闰年");
        }else {
            System.out.println(year + "不是闰年");
        }
    }

    public static void main8(String[] args) {
        int year = 2000;
        if (year % 100 == 0) {
            if (year % 400 == 0) {
                System.out.println(year + "是闰年");
            }else {
                System.out.println("2022不是闰年");
            }
        }else {
            if (year % 4 == 0) {
                System.out.println(year + "是闰年");
            }else {
                System.out.println("2022不是闰年");
            }
        }
    }

    public static void main7(String[] args) {
        int a = 10;
        if (a > 0) {
            System.out.println("a为正数");
        }else if (a < 0) {
            System.out.println("a为负数");
        }else {
            System.out.println("a为零");
        }
    }

    public static void main6(String[] args) {
        //判断一个数字为奇数还是偶数
        int a = 10;
        if (a % 2 == 0) {
            System.out.println("a为偶数");
        }else {
            System.out.println("a为奇数");
        }
    }

    public static void main5(String[] args) {
        int a = 10;
        if (a < 10) {

        }else if (a > 15) {

        }else {

        }
    }

    public static void main4(String[] args) {
        //选择结构
        int a = 10;
        if (a == 10) {
            System.out.println("a == 10");
        }else {
            System.out.println("a != 10");
        }

        int b = 10;
        //不加else的情况
        if (b == 10) {
            System.out.println("b == 10");
        }
            System.out.println("b != 10");

    }

    public static void main3(String[] args) {
        //选择结构
        int a = 10;
        //if(布尔表达式)
/*        if(a == 10) {
            System.out.println("a = 10");
        }*/
        if(a == 10) {
            System.out.println("a = 10");
        }
        if(a == 20) {
            System.out.println("fffff");
        }
    }

    public static void main2(String[] args) {
        //顺序结构
        System.out.println("1");
        System.out.println("2");
        System.out.println("3");
    }

    public static void main1(String[] args) {
        short a =128;

        byte b =(byte) a;

        System.out.println(a);
        System.out.println(b);
    }
}
